package com.zpark.dao.impl;

import com.zpark.dao.SouHuDao;
import com.zpark.pojo.Ranking;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;


//注入dao层bean
@Repository
public class RankingDaoImpl implements SouHuDao {

    //自动注入jdbc模板
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Ranking> selectAll() {
        return jdbcTemplate.query("select * from raking", new BeanPropertyRowMapper<>(Ranking.class));
    }

    @Override
    public Ranking selectById(Integer id) {
        return jdbcTemplate.queryForObject("select * from ranking where id = ?",new BeanPropertyRowMapper<>(Ranking.class),new Object[]{id});
    }

    @Override
    public Integer insert(Ranking ranking) {
        return jdbcTemplate.update("insert into ranking(film_index,film_name,film_actor_name,film_feasibly) values (?,?,?,?)",ranking.getFilmIndex(),ranking.getFilmName(),ranking.getFilmActorName(),ranking.getFilmActorName());
    }

    @Override
    public Integer updateById(Integer id, String fName) {
        return jdbcTemplate.update("update ranking set film_name = ? where id = ?",fName,id);
    }

    @Override
    public Integer deleteById(Integer id) {
        return jdbcTemplate.update("delete from ranking where id = ?",id);
    }
}
